package cn.signalpha.modules.social.controller.admin;

import cn.signalpha.common.constant.AppConstant;
import cn.signalpha.common.dto.IdsDTO;
import cn.signalpha.core.boot.ctrl.BaseController;
import cn.signalpha.core.mp.support.Condition;
import cn.signalpha.core.mp.support.Query;
import cn.signalpha.core.tool.api.R;
import cn.signalpha.core.tool.utils.Func;
import cn.signalpha.modules.base.entity.Complaint;
import cn.signalpha.modules.base.service.ComplaintService;
import cn.signalpha.modules.base.vo.ComplaintVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.Map;

/**
 * 控制器
 *
 * @author signalpha
 */
@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_SOCIAL_NAME + "/admin/complaint")
@Api(value = "投诉", tags = "投诉")
public class ComplaintController extends BaseController {

	private final ComplaintService complaintService;

    @GetMapping("/page")
    @ApiOperation(value = "分页", notes = "")
    @ApiImplicitParams({
		@ApiImplicitParam(name="cause", dataType = "string", value = "原因"),
		@ApiImplicitParam(name="content", dataType = "string", value = "内容"),
		@ApiImplicitParam(name="user", dataType = "string", value = "投诉人搜索"),
		@ApiImplicitParam(name="toUser", dataType = "string", value = "被投诉人搜索"),
		@ApiImplicitParam(name="status", dataType = "string", value = "状态：0未处理 1已处理"),
    })
    public R<IPage<ComplaintVO>> page(@ApiIgnore @RequestParam Map<String, Object> params, Query query) {
        return R.data(complaintService.selectComplaintPage(Condition.getPage(query), params));
    }

	@GetMapping("/info")
	@ApiOperation(value = "详情", notes = "传入id")
	public R<Complaint> info(@ApiParam(value = "主键", required = true) @RequestParam Long id) {
		return R.data(complaintService.getById(id));
	}

    @PostMapping("/handle")
    @ApiOperation(value = "处理", notes = "")
    public R handle(@Valid @RequestBody IdsDTO idsDTO) {
		return R.status(complaintService.update(Complaint.builder().status(1).build(), Wrappers.<Complaint>lambdaUpdate().in(Complaint::getId, Func.toStrList(idsDTO.getIds()))));
    }

	@PostMapping("/remove")
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(complaintService.removeByIds(Func.toLongList(ids)));
	}

}
